<html>
<head><meta charset="utf-8"><title>assume_init vs safety invariant · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html">assume_init vs safety invariant</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="172525589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172525589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172525589">(Aug 05 2019 at 18:16)</a>:</h4>
<p>The <code>MaybeUninit</code> docs warn about validity vs safety (without using that terminology), but <code>assume_init</code> only links to that. Do you think it is worth repeating that warning? <a href="https://github.com/rust-lang/rust/pull/63298" target="_blank" title="https://github.com/rust-lang/rust/pull/63298">https://github.com/rust-lang/rust/pull/63298</a></p>



<a name="172537203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172537203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172537203">(Aug 05 2019 at 20:52)</a>:</h4>
<p>Yes, redundancy is a good thing <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="172539274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172539274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172539274">(Aug 05 2019 at 21:19)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> see mark's comment there. are we okay saying what we are saying about <code>Vec</code>?</p>



<a name="172539352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172539352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172539352">(Aug 05 2019 at 21:20)</a>:</h4>
<p>Let me double check</p>



<a name="172539526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172539526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172539526">(Aug 05 2019 at 21:22)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#guarantees" target="_blank" title="https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#guarantees">https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#guarantees</a></p>



<a name="172539591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172539591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172539591">(Aug 05 2019 at 21:23)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> tho what does 1-initialized <code>Vec&lt;T&gt;</code> mean in terms of code?</p>



<a name="172539610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172539610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172539610">(Aug 05 2019 at 21:23)</a>:</h4>
<p>I reviewed too hastily it seems :D</p>



<a name="172567060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172567060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172567060">(Aug 06 2019 at 07:44)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> tho what does 1-initialized <code>Vec&lt;T&gt;</code> mean in terms of code?</p>
</blockquote>
<p><code>maybe_uninit_vec.as_mut_ptr().write_bytes(1u8, 1)</code></p>



<a name="172567079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172567079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172567079">(Aug 06 2019 at 07:45)</a>:</h4>
<p>or maybe <code>0xFFu8</code> is better</p>



<a name="172567201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172567201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172567201">(Aug 06 2019 at 07:48)</a>:</h4>
<p>I pushed the other edit we talked about</p>



<a name="172567433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init%20vs%20safety%20invariant/near/172567433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/assume_init.20vs.20safety.20invariant.html#172567433">(Aug 06 2019 at 07:53)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> ^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>